package com.springboot.cloud.sysapps.exam.rest;

import com.springboot.cloud.common.core.entity.vo.Result;
import com.springboot.cloud.sysapps.exam.entity.form.QuestionForm;
import com.springboot.cloud.sysapps.exam.entity.po.Question;
import com.springboot.cloud.sysapps.exam.service.IQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/question")
@Api("question")
@Slf4j
public class QuestionController {
    @Autowired
    private IQuestionService questionService;
    @ApiOperation(value = "添加试题", notes = "添加试题")
    @ApiImplicitParam(name = "questionForm", value = "添加试题form表单", required = true, dataType = "QuestionForm")
    @PostMapping
    public Result add(@Valid @RequestBody QuestionForm questionForm){
        log.debug("-----controller add--------{}",questionForm);
        Question question = questionForm.toPo(Question.class);
        return Result.success(questionService.add(question));
    }
}
